package org.spring.batch.ch08;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spring.batch.ch05.model.Group;
import org.springframework.jdbc.core.RowMapper;

/**
 * 类名：HdsjReader<br>
 * 描述：batch计划数读取reader<br>
 * 时间：2015年2月4日下午2:08:35<br>
 * 
 * @author wangjie
 * 
 */
public class PartitionReader extends org.springframework.batch.item.database.JdbcCursorItemReader<Group> {

	private final Logger logger = LoggerFactory.getLogger(getClass());

	/**
	 * 目前用JdbcCursorItemReader来读取
	 */
	@Override
	public Group read() throws Exception {
		String threadName = Thread.currentThread().getName();
		logger.debug("Thread [{}] read item with sql[{}].", threadName, this.getSql());
		return super.read();
	}

	public static class GroupRowMapper implements RowMapper<Group> {
		public GroupRowMapper() {

		}

		@Override
		public Group mapRow(ResultSet rs, int rowNum) throws SQLException {
			Group row = new Group();
			row.setId(rs.getInt("id"));
			row.setName(rs.getString("name"));
			row.setDescription(rs.getString("description"));
			return row;
		}
	}
}
